import { Button, Tag } from "antd";

const checkDisabled = (dict_type: string) => {
  if (dict_type === "sys_user_role") {
    return true;
  }
  return false;
};

export function sysDictTableColumns(editAction: any, deleteAction: any) {
  return [
    {
      title: "ID",
      dataIndex: "id",
      key: "id",
      hidden: true,
    },
    {
      title: "字典ID",
      dataIndex: "dict_id",
      key: "dict_id",
    },
    {
      title: "字典名称",
      dataIndex: "dict_name",
      key: "dict_name",
    },
    {
      title: "字典类型",
      dataIndex: "dict_type",
      key: "dict_type",
    },

    {
      title: "状态",
      dataIndex: "del_flag",
      key: "del_flag",
      render: (state: number) => {
        return (
          <Tag color={state == 1 ? "green" : "red"}>
            {state == 1 ? "正常" : "禁用"}
          </Tag>
        );
      },
    },
    {
      title: "更新时间",
      dataIndex: "update_time",
      key: "update_time",
    },
    {
      title: "补充",
      dataIndex: "other",
      key: "other",
      width: 300,
      render: (state: string, record: any) => {
        // 超出的部分，隐藏
        return (
          <div className="text-center whitespace-nowrap overflow-hidden text-ellipsis w-[300]">
            {state}
          </div>
        );
      },
    },
    {
      title: "操作",
      dataIndex: "action",
      key: "action",
      width: 200,
      render: (state: number, record: any) => (
        <div>
          <Button
            disabled={checkDisabled(record.dict_type)}
            type="primary"
            color="default"
            onClick={() => editAction("edit", record)}
          >
            编辑
          </Button>
          <Button
            disabled={checkDisabled(record.dict_type)}
            className="ml-2"
            danger
            type="primary"
            onClick={() => deleteAction(record)}
          >
            删除
          </Button>
        </div>
      ),
    },
  ];
}
